package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class Demo10 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入id：");
        int id = Integer.parseInt(scanner.nextLine());
        System.out.println("请输入用户名：");
        String username = scanner.nextLine();
        System.out.println("请输入密码：");
        String password = scanner.nextLine();
        System.out.println("请输入昵称：");
        String nickname = scanner.nextLine();
        System.out.println("请输入年龄：");
        int age = Integer.parseInt(scanner.nextLine());

        try(Connection connection =DEUtil.getConnection()) {
            String sql = "UPDATE user SET username=?,password=?,nickname=?,age=? WHERE id=?";
            PreparedStatement preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,username);
            preparedStatement.setString(2,password);
            preparedStatement.setString(3,nickname);
            preparedStatement.setInt(4,age);
            preparedStatement.setInt(5,id);
            int d = preparedStatement.executeUpdate();
            System.out.println(d>0?"修改成功":"修改失败");

        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
